import { Service } from "cl-admin";
import { isArray } from "cl-admin/utils";

import BaseService from "@/service/base";
import qs from "qs";
@Service("OceanEngine")
class OceanEngine extends BaseService {

    // 广告账户账号列表
	accountList({ bra_id = [], ...args }) {
		let params = {
			...args,
		}
		return this.$get("/accountList", { params }).then(res => {
			if (params.showpage != 1) {
				return res;
			}
			return {
				list: res,
				pagination: {
					...params,
					prePage: res.page,
					total: res.total
				}
			};
		});
	}

    oauthUrl(params) {
        return this.$get("/oauthUrl", { params })
    }
    
    addAccount(params) {
        return this.$post("/addAccount", params)
    }

    editAccount(params) {
        return this.$post("/editAccount", params)
    }

	advertiserList(params) {
		return this.$get("/advertiserList", { params }).then(res => {
			return {
				list: res.map(v => {
					return {
						...v,
						children: v.children.map(child => ({
							...child,
							copy: true
						}))
					};
				}),
				pagination: {
					...params,
					total: res.length
				}
			};
		});
	}

	getReport(params) {
		return this.$post('/getAdvertiserReport', params)
	}

	promotionList(params) {
		return this.$get('/promotionList', { params })
	}

	adList(params) {
		return this.$get('/adList', { params })
	}

	newPromotion(params) {
		return this.$post('/newPromotion', params)
	}

	newAd(params) {
		return this.$post('/newAd', params)
	}

	cityCostReport({ date = [], ...args}) {

		let params = { ...args };

		if (date.length) {
			params.begin_time = date[0];
			params.end_time = date[1];
		}

		return this.$get('/cityCostReport', { params })
		.then(res => {
			console.log(res);
			return {
				list: res?.list,
				pagination: {
					page: res.page,
					size: res.size,
					total: res.total
				}
			};
		});
	}
}
export default OceanEngine;